setTimeout(()=>console.log(1),0)  //2 abc 3 4 
async function main(){
    console.log('2')
    await new Promise(resolve=>{   //等待await后面跟的代码执行完毕，才能执行console.log('3)
        console.log('abc')
        setTimeout(resolve,0)
    })
    console.log('3')
}
main()
Promise.resolve().then(()=>console.log('4'))

/**
 * 代码分析
 * 异步队列：setTimeout(1),setTimeout(0)
 * 输出：2，abc 4 1 3
*/

setTimeout(()=>console.log(1),0)  
async function main(){
    console.log('2')
    const res = await new Promise(resolve=>{   //等待await后面跟的代码执行完毕，才能执行console.log('3)
        console.log('abc')
        setTimeout(resolve('abcd'),0)    //setTimeout(resolve('abcd'), 0);  // resolve 被同步调用
    })                                  //resolve('abcd') 会立即执行（而非延迟），setTimeout 实际接收的是 resolve 的返回值（undefined）
    console.log(res,'res')
    console.log('3')
}
main()
Promise.resolve().then(()=>console.log('4'))

//输出结果为：2 abc abcd 3 4 1



setTimeout(()=>console.log(1),0)  
async function main(){
    console.log('2')
    const res = await new Promise(resolve=>{   //等待await后面跟的代码执行完毕，才能执行console.log('3)
        console.log('abc')
        setTimeout(()=>resolve('abcd'),0)
    })                                      
    console.log(res,'res')
    console.log('3') 
}
main()
Promise.resolve().then(()=>console.log('4'))
//输出结果为：2 abc 4 1 abcd 3


setTimeout(()=>console.log(1),0)  
async function main(){
    console.log('2')
    const res = await 'data'                              
    console.log(res,'res')
    console.log('3') 
}
main()
Promise.resolve().then(()=>console.log('4'))

//输出结果为: 2 data 3 4 1


setTimeout(()=>console.log(1),0)  
async function main(){
    console.log('2')
    const test = ()=>{
        console.log('ddd')
        setTimeout(()=>{
            console.log('ffff')
        },0)
    }
    await test()       //await后面跟的不是Promise,await 会将其隐式转换为已解决的 Promise.resolve，‌但不会阻塞‌同步代码                
    console.log('3') 
}
main()
Promise.resolve().then(()=>console.log('4'))
//输出结果为: 2 → ddd → 3 → 4 → 1 → ffff



function test1(){
    console.log('test1')
    return 'bbb'
}
async function test(){
    const data = await test1()  //await后面跟的不是Promise,await 会将其隐式转换为已解决的 Promise.resolve，‌但不会阻塞‌同步代码
    console.log(data,'data')
    console.log('1')
    return '1223'
}
test()
console.log('2')
console.log('3')

//输出结果为：test1 2 3 bbb 1 